package com.dyp.mapstructdemo.service.mapper;


import com.dyp.mapstructdemo.domain.Company;
import com.dyp.mapstructdemo.service.dto.CompanyDTO;
import com.dyp.mapstructdemo.service.mapper.selfdefine.BooleanToStr;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;

/**
 * Mapper for the entity {@link Company} and its DTO {@link CompanyDTO}.
 */
//通过uses配置类型转换
//@Mapper(componentModel = "spring", uses = {PersonMapper.class , BooleanToStr.class})
@Mapper(componentModel = "spring", uses = {PersonMapper.class })
public interface CompanyMapper {
    @Mappings({
            //属性名不一致映射
            @Mapping(source="postalCode", target = "zipCode"),
            @Mapping(source="persons", target = "personDTOS"),
            @Mapping(source="isDisable", target = "isDisable", qualifiedByName = "boolToStr")
    })
    CompanyDTO toDto(Company s);

    @Named("boolToStr")
    default  String toStr(Boolean bool){
        if(bool){
            return "Y";
        }
        else
        {
            return "N";
        }
    }

    @Named("strToBool")
    default Boolean toBool(String str){
        if(str.equalsIgnoreCase("Y")){
            return true;
        }
        else
        {
            return false;
        }
    }

}
